package order

import (
	"fmt"
	"github.com/gin-gonic/gin"
	orderRep "shopstar/forms/api/order"
	"shopstar/reponse"
)

func AddCart(ctx *gin.Context) {
	fmt.Println("add cart ")
	var req orderRep.AddCart

	if err := ctx.ShouldBind(&req); err != nil {
		reponse.HandleValidateError(ctx, err)
		return
	}

	if err := cartService.Add(req.SkuId, req.UserId, req.ShopId, req.Num); err != nil {
		reponse.FailWithErr(err, ctx)
		return
	}

	reponse.OK(ctx)
}

func IndexCart(ctx *gin.Context) {
	reponse.OKWithData(
		cartService.GetCartByUserId(ctx.Query("user_id")),
		ctx,
	)
}
